package player;

import java.util.Scanner;

public class Test {
    //对歌曲类Song进行测试
    public void testSong(){
        Song song1=new Song("s001","两只老虎","小太阳");
        Song song2=new Song("s002","小燕子","风车");
        Song song3=new Song("s003","茉莉花","彩虹");
        System.out.println(song1);
    }

    //对播放列表类PlayList进行测试
    public void testPlayList(){
        //定义几个Song类的对象,添加到播放列表中
        Song song1=new Song("s001","两只老虎","小太阳");
        Song song2=new Song("s002","小燕子","风车");
        Song song3=new Song("s003","茉莉花","彩虹");
        //创建一个PlayList
        PlayList mainPlayList=new PlayList("主播放列表");
        mainPlayList.addToPlayList(song1);
        mainPlayList.addToPlayList(song2);
        mainPlayList.addToPlayList(song3);
        //显示播放列表的内容
        mainPlayList.displayAllSong();
        //通过id查询歌曲信息
        Song song=mainPlayList.searchSongById("s003");
        if (song!=null){
            System.out.println("根据id查询的歌曲信息为:");
            System.out.println(song);
        }else {
            System.out.println("该歌曲不存在!");
        }
        //通过名称查询歌曲信息
        song=null;
        song=mainPlayList.searchSongByName("小燕子");
        if (song!=null){
            System.out.println("根据名称查询的歌曲信息为:");
            System.out.println(song);
        }else {
            System.out.println("该歌曲不存在!");
        }
        //修改歌曲信息
        Song songUpdate=new Song("s005","蜗牛与黄鹂鸟","小太阳");
        mainPlayList.updateSong("s003",songUpdate);
        mainPlayList.displayAllSong();
        //删除歌曲信息
        mainPlayList.deleteSong("s005");
        mainPlayList.displayAllSong();
    }
    //测试播放列表集合类
    public void testPlayListCollection(){
        Song song1=new Song("s001","两只老虎","小太阳");
        Song song2=new Song("s002","小燕子","风车");
        Song song3=new Song("s003","茉莉花","彩虹");
        //创建一个主播放列表
        PlayList mainPlayList=new PlayList("主播放列表");
        //将歌曲添加到主播放列表中
        mainPlayList.addToPlayList(song1);
        mainPlayList.addToPlayList(song2);
        mainPlayList.addToPlayList(song3);
        //定义一个新的播放列表,从主播放列表中添加歌曲进来
        PlayList favouritePlayList=new PlayList("我喜欢");
        favouritePlayList.addToPlayList(mainPlayList.getMusicList().get(0));
        favouritePlayList.addToPlayList(mainPlayList.getMusicList().get(1));
        favouritePlayList.displayAllSong();
        //将两个播放列表添加到播放列表集合中
        PlayListCollection playListCollection=new PlayListCollection();
        playListCollection.addPlayList(mainPlayList);
        playListCollection.addPlayList(favouritePlayList);
        playListCollection.displayListName();
        //根据播放列表的名字查询播放列表信息,并显示所有歌曲
        PlayList playList=playListCollection.searchPlayListByName("我喜欢");
        playList.displayAllSong();
        System.out.println("删除前:");
        playListCollection.displayListName();
        playListCollection.deletePlayList(favouritePlayList);
        System.out.println("删除后:");
        playListCollection.displayListName();
    }
    //主菜单
    public void mainMenu(){
        System.out.println("*************************************");
        System.out.println("                **主菜单**           ");
        System.out.println("               1--播放列表管理         ");
        System.out.println("               2--播放器管理           ");
        System.out.println("               0--退出                ");
        System.out.println("*************************************");
    }
    //播放列表管理菜单
    public void playListMenu(){
        System.out.println("********************************************");
        System.out.println("        **播放列表管理**    ");
        System.out.println("   1--将歌曲添加到主播放列表     ");
        System.out.println("   2--将歌曲添加到普通播放列表    ");
        System.out.println("   3--通过歌曲id查询播放列表中的歌曲");
        System.out.println("   4--通过歌曲名称查询播放列表中的歌曲");
        System.out.println("   5--修改播放列表中的歌曲");
        System.out.println("   6--删除播放列表中的歌曲");
        System.out.println("   7--显示播放列表中的所有歌曲");
        System.out.println("   9--返回上一级菜单");
        System.out.println("********************************************");
    }
    //播放器菜单
    public void playerMenu(){
        System.out.println("********************************************");
        System.out.println("        **播放器管理**    ");
        System.out.println("   1--向播放器添加播放列表     ");
        System.out.println("   2--从播放器删除播放列表    ");
        System.out.println("   3--通过歌曲名字查询播放列表信息");
        System.out.println("   4--显示所有播放列表名称");
        System.out.println("   9--返回上一级菜单");
        System.out.println("********************************************");
    }
    //主流程
    public void test(){
        Test test=new Test();
        Scanner sc=new Scanner(System.in);
        int input1=0,input2=0,input3=0;
        PlayListCollection plc=new PlayListCollection();
        PlayList mainPlayList=new PlayList("主播放列表");
        plc.addPlayList(mainPlayList);
        PlayList favoritePlayList=null;
        while (true){
            test.mainMenu();
            System.out.println("请输入对应数字进行操作:");
            input1=sc.nextInt();
            if (input1==0){
                break;
            }
            switch (input1){
                case 1:
                    while (true){
                        test.playListMenu();
                        System.out.println("请输入对应的数字对播放列表进行管理:");
                        input2=sc.nextInt();
                        if (input2==9){
                            break;
                            }
                        switch (input2){
                            case 1:
                                System.out.println("将歌曲添加到主播放列表");
                                System.out.println("请输入要添加的歌曲的数量:");
                                int count=sc.nextInt();
                                for (int i=1;i<=count;i++){
                                    System.out.println("请输入第"+i+"首歌曲:");
                                    System.out.println("请输入歌曲的id:");
                                    String strId=sc.next();
                                    System.out.println("请输入歌曲的名称:");
                                    String strName=sc.next();
                                    System.out.println("请输入歌曲的演唱者:");
                                    String strSinger=sc.next();
                                    Song song=new Song(strId,strName,strSinger);
//                                    mainPlayList.addToPlayList(song);
                                }
                                mainPlayList.displayAllSong();
                                break;
                            case 2:
                                System.out.println("将歌曲添加到普通播放列表");
                                System.out.println("请输入要添加的播放列表名称:");
                                String sName=sc.next();
                                favoritePlayList=plc.searchPlayListByName(sName);
                                if (favoritePlayList==null){
                                    System.out.println("该播放列表不存在,请先将播放列表添加到播放器中!");

                                }else {
                                    System.out.println("请输入要添加歌曲的数量:");
                                    int count1=sc.nextInt();
                                    for (int i=1;i<=count1;i++){
                                        System.out.println("请输入第"+i+"首歌曲:");
                                        System.out.println("请输入歌曲id:");
                                        String strId=sc.next();
                                        Song song=mainPlayList.searchSongById(strId);
                                        if (song==null){
                                            System.out.println("该歌曲在主播放列表不存在,请继续输入该歌曲的其它信息!");
                                            System.out.println("请输入歌曲名称:");
                                            String strName=sc.next();
                                            System.out.println("请输入演唱者:");
                                            String strSinger=sc.next();
                                            song=new Song(strId,strName,strSinger);
                                            favoritePlayList.addToPlayList(song);
                                            mainPlayList.addToPlayList(song);
                                        }else {
                                            favoritePlayList.addToPlayList(song);
                                        }
                                    }

                                }
                                break;
                            case 3:
                                System.out.println("通过歌曲id查询播放列表中的歌曲");
                                System.out.println("请输入要查询的播放列表名称:");
                                String strPlayListName1=sc.next();
                                PlayList pl=plc.searchPlayListByName(strPlayListName1);
                                if (pl==null){
                                    System.out.println("该播放列表不存在!");
                                    break;
                                }else {
                                    System.out.println("请输入要查询的歌曲id:");
                                    String strId1=sc.next();
                                    Song s=pl.searchSongById(strId1);
                                    if (s==null){
                                        System.out.println("该歌曲在播放列表"+strPlayListName1+"不存在!");
                                    }else {
                                        System.out.println("该歌曲的信息为:");
                                        System.out.println(s);
                                    }
                                }
                                break;
                            case 4:
                                System.out.println("通过歌曲名称查询播放列表中的歌曲");
                                System.out.println("请输入要查询的播放列表名称:");
                                String strPlayListName2=sc.next();
                                PlayList pl2=plc.searchPlayListByName(strPlayListName2);
                                if (pl2==null){
                                    System.out.println("该播放列表不存在!");
                                    break;
                                }else {
                                    System.out.println("请输入要查询的歌曲名称:");
                                    String strName1=sc.next();
                                    Song s1=pl2.searchSongByName(strName1);
                                    if (s1==null){
                                        System.out.println("该歌曲在播放列表"+strPlayListName2+"不存在!");
                                    }else {
                                        System.out.println("该歌曲的信息为:");
                                        System.out.println(s1);
                                    }
                                }
                                break;
                            case 5:System.out.println("修改播放列表中的歌曲");
                                break;
                            case 6:System.out.println("删除播放列表中的歌曲");
                                break;
                            case 7:System.out.println("显示播放列表中的所有歌曲");
                                break;
                            default:
                                System.out.println("该数字没有对应的操作!");
                                break;
                        }
                    }
                    break;
                case 2:
                    while (true){
                        System.out.println("请输入对应的数字对播放器进行管理:");
                        input3=sc.nextInt();
                        if (input3==9){
                            break;
                        }
                        switch (input3){
                            case 1:
                                System.out.println("向播放器添加播放列表");
                                System.out.println("输入要添加的播放列表名称:");
                                String playerName=sc.next();
                                favoritePlayList=new PlayList(playerName);
                                plc.addPlayList(favoritePlayList);
                                break;
                            case 2:System.out.println("从播放器删除播放列表");
                                break;
                            case 3:System.out.println("通过歌曲名字查询播放列表信息");
                                break;
                            case 4:System.out.println("显示所有播放列表名称");
                                break;
                            default:System.out.println("该数字没有对应的操作!");
                                break;
                        }
                    }
                    break;
                default:
                    System.out.println("该数字没有对应的操作!");
                    break;
            }
        }
    }
    public static void main(String[] args) {
        Test test=new Test();
        //test.testSong();
        //test.testPlayList();
        //test.testPlayListCollection();
        test.test();
    }
}
